/* 
* Copyright (C) 2011-2018 ShenZhen iBOXSaaS Information Technology Co.,Ltd. 
* 
* All right reserved. 
* 
* This software is the confidential and proprietary 
* information of iBOXSaaS Company of China. 
* ("Confidential Information"). You shall not disclose 
* such Confidential Information and shall use it only 
* in accordance with the terms of the contract agreement 
* you entered into with iBOXSaaS inc. 
* 
*/

 package com.iboxpay.open.auth.center.validate;

import java.util.List;
import java.util.Map;

import org.iboxpay.open.common.constants.ResultEnums;
import org.iboxpay.open.common.exception.ParamValidateException;
import org.springframework.util.CollectionUtils;

/**
 * 
 * BaseParamValidate.java
 * @author xuxiao
 * @date 2018/06/25
 */
public class BaseParamValidate {
     
     private Map<String, List<ParamValidate>> validates;
     
     public BaseParamValidate(Map<String, List<ParamValidate>> validates) {
        this.validates = validates;
    }

    public void validate(String methodName, Map<String, Object> requestMap) {
        if(CollectionUtils.isEmpty(requestMap)) {
            throw new ParamValidateException(ResultEnums.paramNotNull);
        }
         List<ParamValidate> validateList = validates.get(methodName);
         for(ParamValidate rule : validateList) {
             rule.validate(requestMap);
         }
     }
     
}
